#include "rssthread.h"


UpdateThread::UpdateThread(QObject *parent) : QThread(parent), isReady(false) {
	// Start the worker thread.
	start();
	// Wait for the worker thread to be ready.
	while(!isReady) msleep(50);
}

void UpdateThread::run() {
	UpdateWorker worker;

	// We need to register this because it is not known to Qt's meta-object system.
	qRegisterMetaType< QList<RssFeed*> >("QList<RssFeed*>");

	// Pass sorting requests in the worker thread.
	connect(this, SIGNAL(updateRequested(QList<RssFeed*>,int)),
			&worker, SLOT(updateFeeds(QList<RssFeed*>,int))/*, Qt::QueuedConnection*/);

	// Forward the signal to the clients.
	connect(&worker, SIGNAL(updateFinished()), this,
			SIGNAL(updateFinished())/*, Qt::QueuedConnection*/);

	// Progress for upstream.
	connect(&worker, SIGNAL(progress(int,QString)), this, SIGNAL(progress(int,QString)));

	// Mark the worker thread as ready.
	isReady = true;

	// Event loop (necessary to process signals).
	exec();
}
